package com.gm.blog.service.impl;

import com.gm.blog.exception.BlogException;
import com.gm.blog.mapper.TypeMapper;
import com.gm.blog.pojo.Type;
import com.gm.blog.service.TypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Slf4j
public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public Type getTypeByName(String typeName) {
        return typeMapper.getTypeByName(typeName);
    }

    @Override
    public Type getTypeById(Integer id) {
        return typeMapper.getTypeById(id);
    }

    @Override
    public List<Type> getTypeAll() {
        return typeMapper.getTypeAll();
    }

    @Override
    public void delTypeById(Integer id) {
        typeMapper.delTypeById(id);
    }

    @Override
    public void update(Type type) {
        typeMapper.update(type);
    }

    @Override
    public void insert(Type type) {
        //查询分类是否存在
        Type typeByName = typeMapper.getTypeByName(type.getTypeName());
        if(typeByName!=null){
            throw new BlogException("该分类已存在");
        }

        typeMapper.insert(type);
    }
    @Override
    public List<Type> getFontAll(){
        return typeMapper.getFontAll();
    }

    @Override
    public void enabledById(Integer id) {
        typeMapper.enabledById(id);
    }

    @Override
    public void disabledById(Integer id) {
        typeMapper.disabledById(id);
    }
}
